package cz.muni.fi.pb162.project.geometry;

/**
 * Creates a triangle.
 * 
 * @author Martin Pasko 
 * @version 2012-10-01 project01
*/

public class Triangle extends ArrayPolygon implements Solid
{

    public static final double EPSILON = 0.0001;
    
    /**
     * Creates a triangle
     * 
     * @param vertA vertice of the triangle;
     * @param vertB vertice of the triangle;
     * @param vertC vertice of the triangle;
    */

    public Triangle(Vertex2D vertA, Vertex2D vertB, Vertex2D vertC){
        super(new Vertex2D[] {vertA, vertB, vertC});
    }
    
/*
    public double getWidth(){
        return Math.max(Math.max(pointA.getX(), pointB.getX()), Math.max(pointB.getX(), pointC.getX()))
               - Math.min(Math.min(pointA.getX(), pointB.getX()), Math.min(pointB.getX(), pointC.getX()));
    }
    
    public double getHeight(){
        return Math.max(Math.max(pointA.getY(), pointB.getY()), Math.max(pointB.getY(), pointC.getY()))
               - Math.min(Math.min(pointA.getY(), pointB.getY()), Math.min(pointB.getY(), pointC.getY()));
    }
    
    public double getLength() {
        return pointA.distance(pointB)+pointB.distance(pointC)+pointA.distance(pointC);
    } 
    
    public double getArea(){
        double s = getLength()/2;
        double d1 = pointA.distance(pointB);
        double d2 = pointB.distance(pointC);               // "nadbytocne" lokalne premenne, ale pre prehladnost dobre
        double d3 = pointA.distance(pointC);
        
        return Math.sqrt(s*(s-d1)*(s-d2)*(s-d3));
    }
 */

 /**
 * Rreturns true if distances between three Triangle instances are +/- equal, else returns false
 * 
 * @return true if the triangle is equilateral (0.001 is a tolerated deflection)
 */

    public boolean isEquilateral(){
        return Math.abs(getVertex(0).distance(getVertex(1))-getVertex(1).distance(getVertex(2)))<EPSILON 
               && Math.abs(getVertex(1).distance(getVertex(2))-getVertex(2).distance(getVertex(0)))<EPSILON;
    }
    
}
